Task - Control Flow Statements - Conditional Statements - Looping Statements - while loop #85
Replies: 35 comments
-
1public class Main
{
public static void main(String[] args) {
int naturalNumber=1;
int naturalNumberEnd=10;
int result=0;
while(naturalNumber<=naturalNumberEnd)
{
result+=naturalNumber;
naturalNumber++;
}
System.out.println("sum of natural number:"+result);
}
}2import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the positive number");
int positiveNumber=obj.nextInt();
int tableEnd=10;
int tableStart=1;
while(tableStart<=tableEnd)
{
System.out.println(positiveNumber+"x"+tableStart+"="+(positiveNumber*tableStart));
tableStart++;
}
}
}3import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the factorial number");
int factorialNumber=obj.nextInt();
int result=1;
while(factorialNumber>0)
{
result*=factorialNumber;
factorialNumber--;
System.out.println("result"+result);
}
System.out.println("result"+result);
}
}4import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the number one");
int numberOne=obj.nextInt();
System.out.println("Enter the number two");
int NumberTwo=obj.nextInt();
int result=1;
while(NumberTwo>0)
{
result*=numberOne;
NumberTwo--;
}
System.out.println("result: "+result);
}
}5import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the string");
String sentence=obj.next();
int iterate=0;
int count=0;
int length=sentence.length();
while(length>0)
{
if(sentence.charAt(iterate)=='a')
{
count++;
}
length--;
iterate++;
}
System.out.println("count: "+count);
}
}6import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
System.out.println("Enter the height");
int height=obj.nextInt();
System.out.println("Enter the width");
int width=obj.nextInt();
int temp=width;
while(height>0)
{
temp=width;
while(temp>0)
{
System.out.print("#");
temp--;
}
System.out.print("\n");
height--;
}
}
}import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj=new Scanner(System.in);
boolean pinAccess=true;
final int crctPin=12345;
int count=1;
while(pinAccess)
{
System.out.println("Enter the pin");
int pin=obj.nextInt();
if(pin==crctPin)
{
System.out.println("Correct, welcome back.!");
break;
}else
{
if(count>3)
{
System.out.println("Sorry but you have been locked out.!");
break;
}else{
System.out.println("not correct, try again!");
count++;
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
1public class NaturalNumbers {
public static void main(String[] args) {
int number=1;
int sum=0;
while(number<=10)
{
sum=sum+number;
number++;
}
System.out.println("First 10 natural Numbers sum is "+sum);
}
}2public class MultipilcationTable {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter table number");
int number=scanner.nextInt();
int init=1;
while(init<=10)
{
System.out.printf("%d * %d= %d\n",init,number,(init*number));
init++;
}
scanner.close();
}
}3public class Factorial {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a Factorial");
int number=scanner.nextInt();
int temp=number;
int fact=1;
while(temp>0)
{
fact=fact*temp;
temp--;
}
System.out.printf("Factorial of %d is %d ",number,fact);
scanner.close();
}
}4public class PowerofNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter number 1");
int n1=scanner.nextInt();
System.out.println("Enter number 2");
int n2=scanner.nextInt();
int total=1;
while(n2>0)
{
total=total*n1;
n2--;
}
System.out.println("Power of number is "+total);
scanner.close();
}
}5public class CharacterCount {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter value");
String value=scanner.nextLine();
char[] arr=value.toCharArray();
int i=0;
int count=0;
int length=arr.length;
while(i<length)
{
if(arr[i]=='a')
{
count++;
}
i++;
}
System.out.println("Number of charatcer count is "+count);
scanner.close();
}
}6public class Pattern {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a height");
int height=scanner.nextInt();
System.out.println("Enter a width");
int width=scanner.nextInt();
int temp1=height;
int temp2=width;
while(temp1>0)
{
while(temp2>0)
{
System.out.printf("# ");
temp2--;
}
System.out.println("");
temp2=width;
temp1--;
}
scanner.close();
}
}7public class PinNumber {
public static void main(String[] args) {
String pinNumber="1234";
Scanner scanner = new Scanner(System.in);
int count=1;
while(count<=3)
{
System.out.println("Enter your pin number");
String line = scanner.nextLine();
if(count<=2)
{
if(line.equals(pinNumber))
{
System.out.println("Correct, Welcome back!");
}
else{
System.out.println("Incorrect, try again");
}
}
else{
System.out.println("Sorry but you have been locked out..");
}
count++;
}
scanner.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
Looping Statement1.Natural Numberpackage modules.controlstmnt;
public class NaturalNum {
public static void main(String[] args) {
int sum=0;int i=1;
while(i<=10){
sum+=i;
i++;
}
System.out.println("Sum of first 10 natural numbers is "+sum);
}
}2.Tablepackage modules.controlstmnt;
import java.util.Scanner;
public class PositiveTable {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number :");
int num=sc.nextInt();
int i=1;
if(num>0){
while(i<=10){
System.out.printf("%d * %d = %d\n",num,i,num*i);
i++;
}
}
}}3.Factorialpackage modules.controlstmnt;
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int num=sc.nextInt();
int fact=1;int i=1;
while(i<=num){
fact=fact*i;
i++;
}
System.out.println("Factorial of "+num+ " is "+fact);
}
}4.Powerpackage modules.controlstmnt;
import java.util.Scanner;
public class PowerPrgm {
public static void main(String[] args) {
Scanner sc= new Scanner (System.in);
System.out.println("Enter the number ");
int n1=sc.nextInt();
int n2=sc.nextInt();
int power=1;int i=1;
while(i<=n2){
power = power * n1;
i++;
}
System.out.println(power);
}
}5.Character countpackage modules.controlstmnt;
import java.util.Scanner;
public class CharacterDemo {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the character");
String a=sc.nextLine();
int i=0;
int count=0;
while(i<a.length()){
if(a.charAt(i)=='a')
count++;
i++;
}
System.out.println(count);
}
}6.Heightwidthpackage modules.controlstmnt;
import java.util.Scanner;
public class HeightWidth {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int height=sc.nextInt();
int width=sc.nextInt();
int t1=height;
int t2=width;
while(t1>0)
{
while(t2>0){
System.out.print("# ");
t2--;
}
System.out.println("");
t2=width;
t1--;
}
}
}7.Pinpackage modules.controlstmnt;
import java.util.Scanner;
public class PinProgram {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
final int password=3456;
int count=0;
while(count<3){
System.out.println("Enter the pin");
int pin=sc.nextInt();
if(pin==password){
System.out.println("correct,welcome back.");
break;}
else{
System.out.println("incorrect,try again");
}
count++;
}
if(count==3)
System.out.println("sorry but you have been locked out");
}
} |
Beta Was this translation helpful? Give feedback.
-
1loop1.javaclass loop1 {
public static void main(String[] args) {
int sum=0;
int i = 1;
while (i<= 10) {
sum=sum+i;
i++;
}
System.out.println(sum);
}
}Output2.loop2.javaimport java.util.Scanner;
public class loop2 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int num;
System.out.print("Enter the number: ");
num=Integer.parseInt(sc.nextLine());
int i=1;
while(i<=12)
{
int result=i*num;
System.out.println(String.format("%d x %d = %d",num,i,result));
i++;
}
sc.close();
}
}Output3.loop3.javaimport java.util.Scanner;
public class loop3 {
public static void main(String args[])
{
int temp;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the number: ");
int num=Integer.parseInt(sc.nextLine());
int result=1;
temp=num;
while(num>=1)
{
result=num*result;
num--;
}
System.out.println(String.format("Factorial of %d is %d",temp,result));
sc.close();
}
}Output4.loop4.javaimport java.util.Scanner;
public class loop4 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the value 1: ");
int a=Integer.parseInt(sc.nextLine());
System.out.print("Enter the value 2: ");
int b=Integer.parseInt(sc.nextLine());
int i=1;
int result=1;
System.out.print(String.format("%d to the power of %d is ",a,b));
while(i<=b)
{
result=result*a;
i++;
}
System.out.println(result);
sc.close();
}
}Output5.loop5.javaimport java.util.Scanner;
public class loop5 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String n;
System.out.print("Enter the String: ");
n=sc.nextLine();
char ch[]=n.toCharArray();
int i=1;
try
{
while(ch[i]!='\0')
i++;
}
catch (Exception e){}
int j=0;
int a=0;
try{
while(j<=i)
{
if(ch[j]=='a'|| ch[j]=='A')
{
a++;
}
j++;
}
}
catch (Exception e){}
System.out.println(String.format("a is of %d times",a));
sc.close();
}
}Output6.loop6.javaimport java.util.Scanner;
public class loop6 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the Height: ");
int height=Integer.parseInt(sc.nextLine());
System.out.print("Enter the Width: ");
int width=Integer.parseInt(sc.nextLine());
int i=1;
while(i<=height)
{
int j=1;
while(j<=width)
{
System.out.print("# ");
j++;
}
System.out.println();
i++;
}
sc.close();
}
}Output7.loop7.javaimport java.util.Scanner;
public class loop7 {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
final int pin=1589;
int i=3;
while(i>=1)
{
System.out.print("Enter the pin: ");
int pin1=Integer.parseInt(sc.nextLine());
if(pin1==pin)
{
System.out.println("Correct, welcome back.");
break;
}
else
{
System.out.println("Incorrect, try again.");
}
i--;
if(i==0)
{
System.out.println("Sorry but you have been locked out.");
}
}
sc.close();
}
}Output |
Beta Was this translation helpful? Give feedback.
-
1.NaturalNumpackage Operators.ControlFlow.WhileLoop;
public class NaturalNum {
public static void main(String[] args) {
int i=1;
int sum=0;
while(i<=10){
sum+=i;
i++;
}
System.out.println("Sum of 10 Natural Number is " + sum);
}
}2.Multiplicationpackage Operators.ControlFlow.WhileLoop;
import java.util.Scanner;
public class Multiplication {
public static void main(String[] args) {
int i=1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int a=Integer.parseInt(sc.nextLine());
while(i<=10){
System.out.printf("%d*%d=%d \n",a,i,a*i);
i++;
}
sc.close();
}
}3.Factorialpackage Operators.ControlFlow.WhileLoop;
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
int fact=1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int a=Integer.parseInt(sc.nextLine());
while(a!=0){
fact*=a;
a--;
}
System.out.println("The factorial of a number is: "+fact);
sc.close();
}
}4.Powerpackage Operators.ControlFlow.WhileLoop;
import java.util.Scanner;
public class Power {
public static void main(String[] args) {
int result=1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number 1:");
int a=Integer.parseInt(sc.nextLine());
System.out.println("Enter Number 2:");
int b=Integer.parseInt(sc.nextLine());
while(b>0){
result*=a;
b--;
}
System.out.println("The result is: "+result);
sc.close();
}
}5.CharCountpackage Operators.ControlFlow.WhileLoop;
import java.util.Scanner;
public class CharLooping {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the String: ");
String a=sc.nextLine();
char b[]=a.toCharArray();
int i=0;
while(i<a.length()) {
if(b[i]=='a')
count++;
i++;
}
System.out.println("The count of 'a' is: "+count);
sc.close();
}
}6.Boxpackage Operators.ControlFlow.WhileLoop;
import java.util.Scanner;
public class Box {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the height of the box: ");
int h=Integer.parseInt(sc.nextLine());
System.out.println("Enter the width of the box: ");
int w=Integer.parseInt(sc.nextLine());
int i=0,j;
while(i<h){
j=0;
while(j<w){
System.out.print("# ");
j++;
}
System.out.print("\n");
i++;
}
sc.close();
}
}7.Pinpackage Operators.ControlFlow.WhileLoop;
import java.util.Scanner;
public class Pin {
public static void main(String[] args) {
final String passcode="pass1234";
int count=0;
Scanner sc=new Scanner(System.in);
while(count<3){
System.out.println("Enter the login pin");
String pin=sc.nextLine();
if(pin.equals(passcode)){
System.out.println("Correct, welcome back.");
break;
}
else{
System.out.println("Incorrect, try again.");
}
count++;
}sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
1 sum of the first 10 natural numbersimport java.util.*;
public class NaturalNum{
public static void main(String[] args){
int num = 10, i = 1, sum = 0;
while(i<=num){
sum += i;
i++;
}
System.out.println("Sum of first 10 natural numbers : "+sum);
}
}2 Multiplication table of the numberimport java.util.*;
public class Multiplication{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a positive number : ");
int num = sc.nextInt();
int i=1;
while(i<=10){
System.out.printf("%d*%d=%d\n",num,i,num*i);
i++;
}
}
}
3 Factorialimport java.util.*;
public class Fact{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number : ");
int num = sc.nextInt();
int i=1, fact=1;
while(i<=num){
fact=fact*i;
i++;
}
System.out.println("Factorial of a number : "+fact);
}
}4 Powerimport java.util.*;
public class Power{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a : ");
int a = sc.nextInt();
System.out.println("Enter b: ");
int b = sc.nextInt();
int x = 1, y = b;
while(b!=0){
x = x*a;
b = b-1;
}
System.out.printf("%d raised to the power %d: %d",a,y,x);
}
}5 Characterimport java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter a word :" );
String word = sc.next();
int i=0,count=0;
int ch = word.length();
while(ch>0){
if(word.charAt(i)=='a'){
count++;
}
ch--;
i++;
}
System.out.printf("Number of times 'a' appears in the word : "+count);
}
}6 Boximport java.util.*;
public class Box {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a height : ");
int height=scanner.nextInt();
System.out.println("Enter a width :");
int width=scanner.nextInt();
int a=height;
int b=width;
while(a>0)
{
while(b>0)
{
System.out.printf("# ");
b--;
}
System.out.println("");
b=width;
a--;
}
}
}7 Pinimport java.util.*;
public class Pin{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
String pin = "111";
int pinCount =1;
while(pinCount<=3){
System.out.println("Enter pin number : ");
String pinNumber = scanner.nextLine();
if(pinCount<=2){
if(pinNumber.equals(pin)){
System.out.println("Correct, Welcome back!");
}
else{
System.out.println("Incorrect pin number, try again...");
}
}
else{
System.out.println("Sorry you have been locked out...");
}
pinCount++;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
1public class NaturalNumbers {
public static void main(String[] args) {
int sum = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter 10 numbers :: ");
int i = sc.nextInt();
while (i <= 10) {
sum += i;
i++;
}
System.out.println("sum = " + sum);
}
}2public class PositiveInteger {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number:");
int n = sc.nextInt();
int i=1;
while (i <= 10) {
System.out.println(n+" * "+i+" = "+n*i);
i++;
}
}
}3public class Factorial {
public static void main(String[] args) {
int fact =1, i = 1;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number :: ");
int num = sc.nextInt();
while( i <= num ) {
fact = fact * i;
i++;
}
System.out.println("Factorial of the given number is :: " + fact);
}
}4public class Power {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the base value :: ");
int base = scanner.nextInt();
System.out.println("Enter the exponent value :: ");
int exponent = scanner.nextInt();
int res = 1;
while (exponent != 0) {
res *= base;
--exponent;
}
System.out.println("The power is :: " + res);
}
}5public class Occurences {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the string :: ");
String str = sc.nextLine();
char ch = 'a';
int count = 0, i = 0;
while (i<str.length()) {
if(str.charAt(i) == ch) { count++; }
i++;
}
System.out.println("The character 'a' appears " + count + " times");
}
}6public class Box {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of height :: ");
int h = sc.nextInt();
System.out.println("Enter the value of width :: ");
int w = sc.nextInt();
int temp;
while(h>0) {
temp=w;
while(temp>0) {
System.out.print("#");
temp--;
}
System.out.print("\n");
h--;
}
}
}7public class Pin {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int pin = 123;
int count = 1;
while (true) {
System.out.println("Enter your pin number :: ");
int userpin = sc.nextInt();
if (userpin == pin) {
System.out.println("Correct, welcome back.");
break;
} else {
if (count >= 3) {
System.out.println("Sorry but you have been locked out.");
break;
}
else {
System.out.println("Incorrect, try again.");
count++;
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
1.public class MainClass
{
public static void main(String args[]) {
int number = 1;
int sum = 0;
while (number <= 10) {;
sum = sum + number;
number = number + 1;
}
System.out.println("Sum = " + sum);
}
}2.import java.util.Scanner;
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter number:");
int n=Integer.parseInt(sc.nextLine());
int i=1;
while(i<=10){
System.out.println(n+" * "+i+" = "+n*i);
i++;
}
}
}3.import java.util.Scanner;
class FactorialExample{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int i=1,fact=1;
System.out.print("Enter Number : ");
int number=Integer.parseInt(sc.nextLine());;
while(i<=number){
fact=fact*i;
i++;
}
System.out.println("Factorial of "+number+" is: "+fact);
}
} 4.import java.util.Scanner;
public class MainClass {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("ENTER THE NO : ");
int n1 = Integer.parseInt(sc.nextLine());
System.out.print("ENTER THE POWER FOR THAT NO :");
int n2 = Integer.parseInt(sc.nextLine());
int power = 1;
if (n2 >= 1) {
int i = 1;
while(i <= n2){
power = power * n1;
i++;
}
System.out.println("Power of " + n1 + " is "+power);
}
}
}5.import java.util.Scanner;
public class MainClass
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter String : ");
String input = sc.nextLine();
char search = 'a';
int count=0;
int i=0;
while(i<input.length()){
if(input.charAt(i) == search)
count++;
i++;
}
System.out.println("The Character '"+search+"' appears "+count+" times.");
}
}
6.import java.util.Scanner;
class MainClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Height of the box : ");
int height = Integer.parseInt(sc.nextLine());
System.out.print("Enter width of the box : ");
int width = Integer.parseInt(sc.nextLine());
int outerLoop = 1;
while(outerLoop <= height) {
System.out.print("#");
int innerLoop = 0;
while(innerLoop <= width-2) {
System.out.print("#");
innerLoop++;
}
outerLoop++;
System.out.println();
}
}
}
7.import java.util.Scanner;
class MainClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Please enter pin : ");
int pin = Integer.parseInt(sc.nextLine());
int i=0;
while(i<3) {
if(pin == 1234){
System.out.println("Correct,Welcome Back");
break;
}
else{
if(i<2){
System.out.println("Incorrect, Pease try again..");
System.out.print("Please enter pin : ");
pin = Integer.parseInt(sc.nextLine());
}
i++;
if(i==2){
System.out.print("Sorry, but you have been locked out");
}
}
}
}
}
|
Beta Was this translation helpful? Give feedback.
-
Problem 1 - SumOFNaturalNumberspackage ControlFlowStatement.LoopingStatement;
public class NaturalNumbers {
public static void main(String[] args) {
int num=1,sum=0;
while(num<=10){
sum=sum+num;
num++;
}
System.out.println("The sum of the first 10 natural numbers: " + sum);
}
}Problem 2 - MultiplicationTablepackage ControlFlowStatement.LoopingStatement;
import java.util.Scanner;
public class MultiplicationTable {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter a Integer: ");
int positiveNumber = sc.nextInt();
int num=1;
if(positiveNumber>0){
System.out.println("Mutliplication table of "+positiveNumber+"is: \n");
while(num<=10){
System.out.println(num+" * "+positiveNumber+" = "+num*positiveNumber);
num++;
}
}
else{
System.out.print("Enter a positive number...");
}
sc.close();
}
}Problem 3 - FactorialNumberpackage ControlFlowStatement.LoopingStatement;
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
int number=sc.nextInt();
int factorial=1;
while(number>=1){
factorial = factorial*number;
number--;
}
System.out.println("The factorial of the given number is: "+factorial);
sc.close();
}
}Problem 4 - ExponentPowerpackage ControlFlowStatement.LoopingStatement;
import java.util.Scanner;
public class ExponentPower {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
int number=sc.nextInt();
System.out.print("Enter the exponent: ");
int exponent=sc.nextInt();
int result=1;
if(exponent==0){
System.out.println("The value of number is : 1");
}
else{
while(exponent!=0){
result=result*number;
exponent--;
}
System.out.println("The value of number is: "+result);
}
sc.close();
}
}Problem 5 - Repeatationpackage ControlFlowStatement.LoopingStatement;
import java.util.Scanner;
public class Repeatation {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("Enter a word: ");
String sentence=sc.nextLine();
int count=0;
int iterate=0;
while(iterate<sentence.length()){
if(sentence.charAt(iterate)==('a')){
count++;
}
iterate++;
}
System.out.println("The number of times 'a' appears in the input entered by the user is : "+count);
sc.close();
}
}Problem 6 - AsteriskBoxpackage ControlFlowStatement.LoopingStatement;
import java.util.Scanner;
public class AsteriskBox {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a height : ");
int height=sc.nextInt();
System.out.print("Enter a width :");
int width=sc.nextInt();
int a=height;
int b=width;
while(a>0){
while(b>0){
System.out.printf("# ");
b--;
}
System.out.println("");
b=width;
a--;
}
sc.close();
}
}Problem 7 - CheckPinpackage ControlFlowStatement.LoopingStatement;
import java.util.Scanner;
public class CheckPin {
public static void main(String[] args) {
final String passcode="myjava123";
int count=0;
Scanner sc=new Scanner(System.in);
while(count<3){
System.out.println("Enter the login pin");
String pin=sc.nextLine();
if(pin.equals(passcode)){
System.out.println("Correct, welcome back.");
break;
}
else{
System.out.println("Incorrect, try again.");
}
count++;
}sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
1public class Natural {
public static void main(String[] args){
int num=1,sum=0;
while(num<=10){
sum=sum+num;
System.out.println("number="+num);
num++;
}
System.out.println("The sum of first 10 Natural numbers is:"+sum);
}
}2import java.util.Scanner;
public class Multiplication {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the multiplication table");
int table=scanner.nextInt();
int num=1;
while(num<=10){
int multiplication=num*table;
System.out.println(String.format("The multplication table of %d is:",table)+multiplication);
num++;
}
}
}
3import java.util.Scanner;
public class Factorial {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number");
int num=scanner.nextInt();
int a=1,fact=1;
while(a<=num){
fact=fact*a;
a++;
}
System.out.println("The fatorial of number is :"+fact);
}
}4import java .util.Scanner;
public class Power {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the base");
int base=scanner.nextInt();
System.out.println("Enter the exponent ");
int exponent=scanner.nextInt();
int power=1,a=1;
while(a<=exponent){
power=power*base;
a++;
}
System.out.println("The Power of number is: "+power);
}
}5import java.util.Scanner;
public class NumberOfTimes {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter any word:");
String word=sc.nextLine();
char[] array=word.toCharArray();
int len=array.length;
System.out.println("len: " + len);
int i=0,count=0;
while(i<len){
if(array[i]=='a'){
count++;
}
i++;
}
System.out.println("The count of a is: " + count);
}
}6import java.util.Scanner;
public class BoxSymbols {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the height");
int height = scanner.nextInt();
System.out.println("Enter the width");
int width = scanner.nextInt();
int a;
while(height>0){
a=width;
while(a>0){
System.out.print("#");
a--;
}
System.out.print("\n");
height--;
}
}
}7import java.util.Scanner;
class PinNumber {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int pin=123;
int count=1;
while(true){
System.out.println("Enter pin number");
int pinNumber = scanner.nextInt();
if(pinNumber==pin){
System.out.println("PinNumber is Correct, welcome back");
break;
}
else
if(count>=3){
System.out.println("Sorry,you have been locked out");
break;
}
else{
System.out.println("Incorrect pin,try again");
count++;
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
1public class Ques1 {
public static void main(String[] args) {
int n=1;
int sum=0;
while(n<=10){
sum+=n;
n++;
}
System.out.println("Sum of 10 Natural Number is " + sum);
}
}2import java.util.Scanner;
public class Ques2 {
public static void main(String[] args) {
int i=1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int a=sc.nextInt();
while(i<=10){
System.out.printf("%d*%d=%d \n",a,i,a*i);
i++;
}
sc.close();
}
}3import java.util.Scanner;
public class Ques3 {
public static void main(String[] args) {
int fact=1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number: ");
int a=sc.nextInt();
while(a!=0){
fact*=a;
a--;
}
System.out.println("The factorial of a number is: "+fact);
sc.close();
}
}4import java.util.Scanner;
public class Ques4 {
public static void main(String[] args) {
int res=1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number 1:");
int num1=sc.nextInt();
System.out.println("Enter Number 2:");
int num2=sc.nextInt();
while(num2>0){
res*=num1;
num2--;
}
System.out.println(res);
sc.close();
}
}5import java.util.Scanner;
public class Ques5 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int count=0;
System.out.println("Enter the String: ");
String s=sc.nextLine();
char b[]=s.toCharArray();
int i=0;
while(i<s.length()) {
if(b[i]=='a')
count++;
i++;
}
System.out.printf("The count of 'a' is: %d",count);
sc.close();
}
}6import java.util.Scanner;
public class Ques6{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the height of the box: ");
int he=Integer.parseInt(sc.nextLine());
System.out.println("Enter the width of the box: ");
int wi=Integer.parseInt(sc.nextLine());
int i=0,j=0;
while(i<he){
j=0;
while(j<wi){
System.out.print("# ");
j++;
}
System.out.print("\n");
i++;
}
sc.close();
}
}7import java.util.Scanner;
public class Ques7 {
public static void main(String[] args) {
final String passcode="Pass123";
int count=0;
Scanner sc=new Scanner(System.in);
while(count<3){
System.out.println("Enter the login pin");
String pin=sc.nextLine();
if(pin.equals(passcode)){
System.out.println(" Welcome back.");
break;
}
else{
System.out.println("Incorrect pin , try again.");
}
}sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
1.public class NaturalSum {
public static void main(String[] args) {
int i = 1, s = 0;
while (i <= 10) {
s += i;
i++;
}
System.out.println("Sum of first 10 natural numbers is " + s);
}
}2.import java.util.Scanner;
public class MultipTable {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a positive unteger");
int n = Integer.parseInt(sc.nextLine());
int i = 1;
while (i <= 10) {
System.out.println(i + " * " + n + " = " + (i * n));
i++;
}
sc.close();
}
}3.import java.util.Scanner;
public class Factori {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int n = sc.nextInt();
int f = 1, i = 1;
while (i <= n) {
f = f * i;
i++;
}
System.out.println("The factorial of " + n + " is " + f);
sc.close();
}
}4.import java.util.Scanner;
public class Power {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter two numbers");
int a = Integer.parseInt(sc.nextLine());
int b = Integer.parseInt(sc.nextLine());
int t = b;
int r = 1;
while (b != 0) {
r *= a;
--b;
}
System.out.println(String.format("Value of %d power %d is %d", a, t, r));
sc.close();
}
}5.import java.util.Scanner;
public class CharCount {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a word");
String s = sc.next();
int i = 0, n = s.length();
int c = 0;
while (i < n) {
if (s.charAt(i) == 'a') {
c++;
}
i++;
}
System.out.println(String.format("The character 'a' apperrs %d times in the word %s", c, s));
sc.close();
}
}6.import java.util.Scanner;
public class PrintBox {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter height and width values");
int h = Integer.parseInt(sc.nextLine());
int w = Integer.parseInt(sc.nextLine());
int i = 0, j = 0;
while (i < h) {
j = 0;
while (j < w) {
System.out.print("# ");
j++;
}
System.out.println();
i++;
}
sc.close();
}
}7.import java.util.Scanner;
public class Password {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int p = 1234;
int i = 0;
int uspin = 0;
// int f = 0;
while (i < 3) {
System.out.println("Enter pin number");
uspin = Integer.parseInt(sc.nextLine());
if (uspin == p) {
System.out.println("Correct, welcome back");
break;
} else {
System.out.println("Incorrect, try again");
}
i++;
if (i == 3) {
System.out.println("Sorry but you have been locked out.");
}
}
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
TASK -LOOPING STATEMENTS1.SumDemo.javaimport java.util.Scanner;
public class SumDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER A NUMBER");
int n=sc.nextInt();
int sum=0;
int i=1;
while(i<=n)
{
sum=sum+i;
i++;
}
System.out.println("sum of first "+n+" natural number is "+sum);
}
}2.TablesDemo.java3.FactorialDemo.javaimport java.util.Scanner;
public class FactorialDemo {
public static void main(String[] args) {
int fact = 1,n;
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE NUMBER:");
n=sc.nextInt();
if(n==0)
{
System.out.println("factorial of 0 is 1");
}
int i=1;
while(i<=n)
{
fact=fact*i;
i++;
}
System.out.println("factorial of"+" "+n+" "+"is"+" "+fact );
}
}4.ValueDemo.javapackage ControlFlowStatements;
import java.util.Scanner;
public class ValueDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE NUM-1:");
int base=sc.nextInt();
System.out.println("ENTER THE NUM-2:");
int exponent=sc.nextInt();
long result = 1;
int i=1;
while (i<=exponent) {
result = result * base;
i++;
}
System.out.println("Answer = " + result);
}
}5.CountDemo.javapackage ControlFlowStatements;
import java.util.Scanner;
public class CountDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string :");
String a=sc.next();
int count=0,i=0;
char temp;
while(a!=null && i<a.length())
{
temp=a.charAt(i);
if(temp=='a')
{
count++;
}
i++;
}
System.out.println("No of times a found is "+count);
}
}6.Box.javapackage ControlFlowStatements;
import java.util.Scanner;
public class Box {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the height of the box");
int h=sc.nextInt();
System.out.println("Enter the width of the box");
int w=sc.nextInt();
int i=0,j;
while(i<h)
{
j=0;
while(j<w)
{
System.out.print("# ");
j++;
}
System.out.println();
i++;
}
}
}7.PasswordDemo.javapackage ControlFlowStatements;
import java.util.Scanner;
public class PasswordDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
final int password=1810;
int i=0;
while(i<3)
{
System.out.println("Enter password :");
int passcode=sc.nextInt();
if(passcode==password)
{
System.out.println("Correct !! Welcome Back!");
break;
}
else{
System.out.println("Password incorrect!!");
}
i++;
if(i==3)
System.out.println("Sorry!! you have been locked out!!!");
}
}
} |
Beta Was this translation helpful? Give feedback.
-
1public class Examples
{
public static void main(String args[]) {
int num = 1;
int sum = 0;
while (num <= 10) {;
sum = sum + num;
num = num + 1;
}
System.out.println("Sum = " + sum);
}
}2import java.util.Scanner;
public class Examples
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number:");
int n=Integer.parseInt(sc.nextLine());
sc.close();
int i=1;
while(i<=10){
System.out.println(n+" * "+i+" = "+n*i);
i++;
}
}
}3import java.util.Scanner;
class Examples{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int i=1,fact=1;
System.out.print("Enter Number : ");
int number=Integer.parseInt(sc.nextLine());;
sc.close();
while(i<=number){
fact=fact*i;
i++;
}
System.out.println("Factorial of "+number+" is: "+fact);
}
} 4import java.util.Scanner;
public class Examples {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number : ");
int n1 = Integer.parseInt(sc.nextLine());
System.out.print("Enter the power to be raised:");
int n2 = Integer.parseInt(sc.nextLine());
int power = 1;
if (n2 >= 1) {
int i = 1;
while(i <= n2){
power = power * n1;
i++;
}
System.out.println("Power of " + n1 + " is "+power);
}
}
}5import java.util.Scanner;
public class Examples
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a String : ");
String input = sc.nextLine();
char search = 'a';
int count=0;
int i=0;
while(i<input.length()){
if(input.charAt(i) == search)
count++;
i++;
}
System.out.println("The Character '"+search+"' appears "+count+" times.");
}
}
6import java.util.Scanner;
class Examples {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Height of the box : ");
int height = Integer.parseInt(sc.nextLine());
System.out.print("Enter width of the box : ");
int width = Integer.parseInt(sc.nextLine());
int outerLoop = 1;
while(outerLoop <= height) {
System.out.print("#");
int innerLoop = 0;
while(innerLoop <= width-2) {
System.out.print("#");
innerLoop++;
}
outerLoop++;
System.out.println();
}
}
}7import java.util.Scanner;
public class Examples {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int pin = 123;
int count = 1;
while (true) {
System.out.println("Enter your pin number :: ");
int userpin = sc.nextInt();
if (userpin == pin) {
System.out.println("Correct, welcome back.");
break;
} else {
if (count >= 3) {
System.out.println("Sorry but you have been locked out.");
break;
}
else {
System.out.println("Incorrect, try again.");
count++;
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
1package WhileLoop;
/*Write a program to calculate the sum of the first 10 natural numbers.*/
public class While1 {
public static void main(String[] args) {
int i=1;
int sum=0;
while(i<=10){
sum+=i;
i++;
}
System.out.println(sum);
}
}2package WhileLoop;
import java.util.Scanner;
/*Write a program that prompts the user to input a positive integer. It should then print the multiplication table of that number.
*/
public class While2 {
public static void main(String[] args) {
int count=0, i=1;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Positive Integer");
int num = sc.nextInt();
if(num >0)
while (i<=10) {
System.out.println("The Table is " + num+"*" +i+"="+num*i);
i++;
}
sc.close();
}
}3package WhileLoop;
import java.util.Scanner;
/*Write a program to find the factorial value of any number entered through the keyboard. Example: factorial 4 = 4 * 3 * 2 * 1 = 24*/
public class While3 {
public static void main(String[] args) {
int fact=1,num=1;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int i =sc.nextInt();
while(num<=i){
fact = fact*num;
num++;
}
System.out.println(fact);
sc.close();
}
}4package WhileLoop;
import java.util.Scanner;
/*Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another. (Do not use Java built-in method)*/
public class While4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter I value: ");
int i = sc.nextInt();
System.out.println("Enter the J value: ");
int j = sc.nextInt();
int power=1;
while (j>0) {
power=power*i;
j--;
}
System.out.println("The exponent"+power);
sc.close();
}
}5import java.util.Scanner;
public class While5 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string :");
String a=sc.next();
int count=0,i=0;
char temp;
while(a!=null && i<a.length())
{
temp=a.charAt(i);
if(temp=='a')
{
count++;
}
i++;
}
System.out.println("No of times a found is "+count);
}
}6public class While6{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the height of the box: ");
int he=Integer.parseInt(sc.nextLine());
System.out.println("Enter the width of the box: ");
int wi=Integer.parseInt(sc.nextLine());
int i=0,j=0;
while(i<he){
j=0;
while(j<wi){
System.out.print("# ");
j++;
}
System.out.print("\n");
i++;
}
sc.close();
}
}7import java.util.Scanner;
public class While7 {
public static void main(String[] args) {
final String passcode="Pass123";
int count=0;
Scanner sc=new Scanner(System.in);
while(count<3){
System.out.println("Enter your Pin");
String pin=sc.nextLine();
if(pin.equals(passcode)){
System.out.println(" Welcome .");
break;
}
else{
System.out.println(" Sorry Incorrect pin.");
}
}sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
import java.util.*;
public class Loop2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write a program to calculate the sum of the first 10 natural numbers.
int sum = 0;
for (int i = 1; i <= 10; i++) {
sum = sum + i;
}
System.out.println(sum);
// Write a program that prompts the user to input a positive integer. It should
// then print the multiplication table of that number.
System.out.println("Enter a positive integer:");
int num = sc.nextInt();
for (int i = 1; i <= 10; i++) {
System.out.printf("%d * %d = %d%n", num, i, num * i);
}
// Write a program to find the factorial value of any number entered through the
// keyboard.
System.out.println("Enter a number:");
int n1 = sc.nextInt();
int p = 1;
for (int i = n1; i > 0; i--) {
p = p * i;
}
System.out.println("Factorial value is " + p);
// Two numbers are entered through the keyboard. Write a program to find the
// value of one number raised to the power of another
System.out.println("Enter two numbers: ");
int x = sc.nextInt();
int y = sc.nextInt();
int pow = 1;
for (int i = 0; i < y; i++) {
pow = pow * x;
}
System.out.println("Power is: " + pow);
// Determine and print the number of times the character ‘a’ appears in the
// input entered by the user.
System.out.println("Enter the string: ");
String str = sc.next();
int count = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'a') {
count++;
}
}
System.out.println(count);
// Write a program that will print a box of #’s taking from the user the height
// and width values.
System.out.println("Enter height: ");
int h = sc.nextInt();
System.out.println("Enter width: ");
int br = sc.nextInt();
for (int i = 0; i < h; i++) {
for (int j = 0; j < br; j++) {
System.out.print("# ");
}
System.out.println();
}
// Pin display
int pin = 4567;
int t = 0;
int ct = 0;
while (t < 3) {
System.out.println("Enter the correct pin");
int p = sc.nextInt();
if (p == pin) {
System.out.println("Correct, welcome back.");
break;
} else {
System.out.println("Incorrect, try again.");
ct++;
}
t++;
}
if (ct == 3) {
System.out.println("Sorry but you have been locked out");
}
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
1import java.util.*;
public class Main {
public static void main(String[] args) {
int n = 10;
int sum = 0;
sum = n * (n + 1) / 2;
System.out.println(sum);
}
} |
Beta Was this translation helpful? Give feedback.
-
3import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
int fact = 1;
for(int i = 1; i <= n; i++){
fact *= i;
}
System.out.println(fact);
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
7import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int pin = 1234;
int count = 1;
boolean condition = true;
while(condition){
System.out.println("Enter the Pin To Unlock:");
int enteredPin = Integer.parseInt(sc.nextLine());
if(enteredPin == pin){
System.out.println("Correct, Welcome back !!!");
break;
}else{
if(count => 3){
System.out.println("Sorry but you have been locked out");
condition = false;
}else{
System.out.println("Incorrect, try again.");
count++;
}
}
}
sc.close();
}
} |
Beta Was this translation helpful? Give feedback.
-
//FACTORIAL
class A{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
int fact=1;
int n=Integer.parseInt(sc.nextLine());
for(int i=1;i<=n;i++)
{
fact*=i;
}
System.out.println(fact);
}
}
|
Beta Was this translation helpful? Give feedback.
-
//PROG 7
class A{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
final int lock=123;
int i=0;
int count=0;
for(;i<3;i++)
{
int n=Integer.parseInt(sc.nextLine());
if(n==123)
{
System.out.println("Correct, welcome back");
}
else {
count+=1;
if(count==3)
{
System.out.println("Sorry but you have been locked out.");
break;
}
System.out.println("Incorrect, try again");
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
public class Main { }` |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
import java.util.; |
Beta Was this translation helpful? Give feedback.
-
Code1public class A {
public static void main(String[] args) {
int sum = 0;
int num = 10;
for (int i = 1; i <= num; i++) {
sum = sum+i;
}
System.out.println("sum of first 10 natural number is :"+ sum);
}
} |
Beta Was this translation helpful? Give feedback.
-
Code3import java.util.Iterator;
import java.util.Scanner;
public class B {
public static void main(String[] args) {
int fact = 1;
Scanner s = new Scanner(System.in);
System.out.println("Enter the Number");
int num = Integer.parseInt(s.next());
for (int i = 1; i <=num; i++) {
fact= fact*i;
}
System.out.println("Factorial value: "+ fact);
}
} |
Beta Was this translation helpful? Give feedback.
-
Code7import java.util.Scanner;
public class C {
public static void main(String[] args) {
final int pass = 1201;
Scanner s = new Scanner(System.in);
System.out.println("Enter your pin:");
int pin = Integer.parseInt(s.next());
int i = 0;
while(i<3) {
if(pin==pass) {
System.out.println("Correct, Welcome back");
break;
}
else {
if(i>3) {
System.out.println("Sorry but you have been logged out.!");
break;
}else {
System.out.println("Incorrect, try again.");
i++;
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Java1public class Main Java2import java.util.Scanner; } Java3import java.util.Scanner; Java4import java.util.Scanner; } Java5import java.util.Scanner; } |
Beta Was this translation helpful? Give feedback.













Uh oh!
There was an error while loading. Please reload this page.
-
Write a program to calculate the sum of the first 10 natural numbers.
Write a program that prompts the user to input a positive integer. It should then print the multiplication table of that number.
Write a program to find the factorial value of any number entered through the keyboard. Example: factorial 4 = 4 * 3 * 2 * 1 = 24
Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another. (Do not use Java built-in method)
Determine and print the number of times the character ‘a’ appears in the input entered by the user.
Write a program that will print a box of #’s taking from the user the height and width values.
You have to design the code such that the user has only three tries to guess the correct pin of the account. You set the pin as a constant with a final attribute. When correct display “Correct, welcome back.” When incorrect display “Incorrect, try again.”. When ran out of tries display “Sorry but you have been locked out.”
Beta Was this translation helpful? Give feedback.
All reactions