Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 61.
- package com.company;
- import java.util.*;
- import java.lang.*;
- public class ExamScores {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- int min = 100;
- int max = 0;
- int avg;
- int gradeSum = 0;
- System.out.println("Please type 10 of your grades.");
- int grade = input.nextInt();
- int counter = 1;
- gradeSum += grade;
- while(counter <= 10) {
- if (grade < 0 || grade > 100) {
- System.out.println("This grade is invalid");
- counter = 13;
- } else {
- if (grade < min) {
- min = grade;
- }
- if (grade > max) {
- max = grade;
- }
- if (counter != 10) {
- System.out.println("Please type another one of your grades.");
- grade = input.nextInt();
- gradeSum += grade;
- }
- counter++;
- }
- }
- avg = gradeSum/10;
- if(counter == 11) {
- System.out.println("The smallest number that you typed is " + min);
- System.out.println("The largest number that you typed is " + max);
- System.out.println("The average of the numbers is " + avg);
- }
- }
- }
- 63.
- package com.company;
- import java.util.*;
- import java.lang.*;
- public class IDentifier {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Type in your ID");
- String id = input.next();
- int length = id.length();
- int counter = 0;
- int digitCounter = 0;
- char currentChar = id.charAt(counter);
- while(counter < length-1){
- if( currentChar == '1'||currentChar == '2'||currentChar == '3'||currentChar == '4'||currentChar == '5'||currentChar =='6'||currentChar == '7'||currentChar == '8'||currentChar == '9'||currentChar == '0'){
- digitCounter++;
- }
- counter++;
- currentChar = id.charAt(counter);
- }
- if(digitCounter == 2){
- System.out.println("The id is valid");
- }
- else{
- System.out.println("The id is invalid");
- }
- }
- }
- 65.
- package com.company;
- import java.util.*;
- import java.lang.*;
- public class BinaryToDecimal {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Type in a binary number");
- String binaryNum = input.next();
- System.out.println("The binary form is: "+Integer.parseInt(binaryNum,2));
- }
- }
- 67.
- package com.company;
- import java.util.*;
- import java.lang.*;
- public class PalindromeChecker {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Type in a sentence");
- String word = input.nextLine();
- String trueWord = word.toLowerCase();
- int length = trueWord.length();
- int counter1 = 0;
- int truthChecker = 1;
- char currentLetter1 = trueWord.charAt(counter1);
- for(int i = 1; i < length; i++){
- if(currentLetter1 == trueWord.charAt(length-i)){
- counter1++;
- currentLetter1 = trueWord.charAt(counter1);
- truthChecker++;
- }
- }
- if(truthChecker==length){
- System.out.println("This is a palindrome");
- }
- else
- {
- System.out.println("Not a palindrome");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement