I have uploaded all my projects in C, C++, HTML, CSS, Java, and Android Development Projects in a topic-wise sequential manner.
Further posts are uploaded on https://mohitx001.blogspot.com/
public class Ch5_21_WhileLoop { public static void main(String[] args) { //Quick Quiz int i = 100; while (i <= 200) { System.out.print(i + " "); i++; } } }
package com.company ; import java.util.Random ; import java.util.Scanner ; public class Ch9_43_Ex3_GuessTheNumber { public static void main ( String [] args ) { Random rand = new Random (); int rand_num = rand . nextInt ( 100 ); System . out . println ( rand_num ); Scanner scan = new Scanner ( System . in ); int guessed_num = - 1 ; int numberOfGuesses = 1 ; while ( guessed_num != rand_num ) { System . out . println ( "Guess the number: " ); guessed_num = scan . nextInt (); if ( guessed_num > rand_num ) { System . out . println ( "Aww ...Too big number." ); numberOfGuesses ++; } else if ( guessed_num < rand_num ) { System . out . println ( "Oops...its a small number." ); numberOfGuesses ++; } } System . out . println ( "yehh...You got the number in...
package com.company.Ch3_15_PracticeSet ; import java.util.Scanner ; public class PS_Ch3_Q4 { public static void main ( String [] args ) { Scanner scan = new Scanner ( System . in ); System . out . println ( "Enter any string." ); String str = scan . nextLine (); int index = str . indexOf ( " " ); System . out . println ( "Double or triple spaces are at index : " + index ); } }
package com.company.Ch6_29_PracticeSet ; import java.util.Scanner ; public class PS_Ch6_Q8 { public static void main ( String [] args ) { Scanner scan = new Scanner ( System . in ); System . out . println ( "Enter the values in array" ); int [] arr = new int [ 5 ]; for ( int i = 0 ; i < arr . length ; i ++) { arr [ i ] = scan . nextInt (); } boolean isSorted = true ; for ( int i = 0 ; i < arr . length - 1 ; i ++) { if ( arr [ i ] > arr [ i + 1 ]) { isSorted = false ; break ; } } if ( isSorted ) { System . out . println ( "The array is Sorted." ); } else { System . out . println ( "The array is not Sorted." ); } } }
Comments
Post a Comment