/** * Performs unbounded integer exponentiation with a user-specified * base and exponent. This version uses dialog boxed for I/O. * * @author Justin Yoder */ import java.util.Scanner; import java.math.BigInteger; import javax.swing.JOptionPane; public class PowerCalculator3 { public static void main(String[] args) throws Exception{ // prompt the user and read input String prompt = "Enter two integers (base and exponent)"; String input = JOptionPane.showInputDialog(prompt); // extract base and exponent from input string Scanner scan = new Scanner(System.in); BigInteger base = scanner.nextBigInteger(); int exponent = scanner.nextInt(); // format and display result BigInteger result = base.pow(exponent); String output = base + "^" + exponent + " = " + result; JOptionPane.showMessageDialog(nul, output); } }
import java.text.NumberFormat; import java.math.BigInteger; /** * Calculates 2^64 and outputs the result as a currency ammount with commas or * decimals to seperate thousands based on locale. * * @author Willy Ferreiras */ public class PowerCalculator{ public static void main(String[] args){ BigInteger two = new BigInteger("2"); BigInteger num = two.pow(64).subtract(BigInteger.ONE); /* line 14 subtracts 1 from result of num instead of 64 because BigInteger objects cannot be changed once created */ // Get a formatter for the current locale NumberFormat nf = NumberFormat.getInstance(); // recognizes current locale of user's machine // Display dollar amount String sym = nf.getCurrency().getSymbol(); System.out.println(sym + nf.format(num)); } }
import java.util.Scanner; import java.math.BigInteger; import java.text.NumberFormat; /** * Calculates 2^64 and outputs the result as a dollar amount with commas * to separate thousands. * * @author Taylor Raker * @version September 18, 2017 */ public class NumberFormatDemo { public static void main(String[ ] args) { BigInteger two = new BigInteger("2"); BigInteger num = two.pow(64); // get formatter for the current locale NumberFormat nf = NumberFormat.getInstance(); //display dollar amount String currencySymbol = nf.getCurrency().getSymbol(); System.out.println(currencySymbol + nf.format(num)); } }
import java.util.Scanner; import java.math.BigInteger; /* Performs unbounded integer exponention with a user-specified base and exponent. @author Jake Nocentino @version September 13, 2017 */ public class PowerCalculator { public static void main(String[] args) { // prompt the user and read input System.out.print("Enter two integers (base and exponent): "); Scanner in = new Scanner(System.in); String baseString = in.next(); int exp = in.nextInt(); // calculate result BigInteger base = new BigInteger(baseString); BigInteger result = base.pow(exp); // format and display results String output = base + "^" + exp + " is " + result; System.out.println(output); } }
public class HelloWorld{ public static void main(String []args){ System.out.println("Hello World"); } }
public class HelloWorld{ public static void main(String []args){ System.out.println("Hello World"); } }
import java.io.*; import java.util.*; /* * Problem Statement : Shift all 0's to left in time complexity O(n) */ public class NonZeroShift { public static void main(String[] args) { int[] input = {6,4,0,5,0,0,1,6}; System.out.println("Input array is : "); for (int i : input) { System.out.print(i+" "); } System.out.println(); int[] output = sortNonZero(input); System.out.println("New array is : "); for (int i : output) { System.out.print(i+" "); } } private static int[] sortNonZero(int[] input){ int temp = -1; for(int i =input.length-1; i > -1; i--){ if(input[i] == 0 && temp ==-1){ temp = i; }else if (temp != -1 && input[i] != 0){ int temp1 = input[temp]; input[temp] = input[i]; input[i] = temp1; temp--; } } return input; } }
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Squares { public static void main (String[] args) throws java.lang.Exception { int i, j, n; String gmr; System.out.println("Please enter length " + "\n"); Scanner sc = new Scanner(System.in); n = Integer.parseInt(sc.nextLine()); for (j=0; j < n; j++) { for(i=0; i <n; i++){ System.out.print("*"); } System.out.println(); } } }
public class HelloWorld{ class Machine { public void machineFirst() { System.out.println("this is first overload"); } } class Car extends Machine { public void machineFirst() { System.out.println("this is second overload"); } } public class Manual { public static void main(String[] args) { Machine obj=new Machine(); Car car= new Car(); obj.machineFirst(); car.machineFirst(); } } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more