0% found this document useful (0 votes)
101 views14 pages

Beg Qstns

The document describes a static method called countLastDigits that accepts an integer array as a parameter and examines the elements to determine how many end in each digit from 0-9. It returns an array where the count of elements ending in 0 is stored at index 0, ending in 1 at index 1, and so on. It provides an example input and output. The given code is a Java program that implements this countLastDigits method. It contains a main method that tests it on a sample input array.

Uploaded by

Praveen Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views14 pages

Beg Qstns

The document describes a static method called countLastDigits that accepts an integer array as a parameter and examines the elements to determine how many end in each digit from 0-9. It returns an array where the count of elements ending in 0 is stored at index 0, ending in 1 at index 1, and so on. It provides an example input and output. The given code is a Java program that implements this countLastDigits method. It contains a main method that tests it on a sample input array.

Uploaded by

Praveen Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Write a static method named countLastDigits that accepts an array of integers as a parameter and

examines its elements to determine how many of the integers end in 0, how many end in 1, how
many end in 2 and so on. Your method will return an array of counters. The count of how many
elements end in 0 should be stored in its element [0], how many of the values end in 1 should be
stored in its element [1], and so on. For example, if a variable named list refers to an array
containing the values {9, 29, 44, 103, 2, 52, 12, 12, 76, 35, 20}, the call of countLastDigits(list)
should return an array containing {1, 0, 4, 1, 1, 1, 1, 0, 0, 2} because 1 element ends with 0 (20),
no elements end with 1, 4 elements end with 2 (2, 52, 12, 12), and so on.
Test your code with the following class:
import java.util.*;

public class TestCountLastDigits {


public static void main(String[] args) {
int[] list = {9, 29, 44, 103, 2, 52, 12, 12, 76, 35, 20};
int[] count = new int[10];
countLastDigits(list, count);

System.out.println(Arrays.toString(list)); // [9, 29, 44, 103, 2, ...]


System.out.println(Arrays.toString(count)); // [1, 0, 4, 1, 1, 1, 1, 0, 0, 2]
}

// finish me
}

Write a program that hash 100 numbers into a hash table using a load factor of
75%. Please print your input file and then print the table once it is hashed.
Can somebody troubleshoot this
package Analysis;
public class AnalysisUI extends javax.swing.JFrame {
public AnalysisUI();
{
initComponents();
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jButton1 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();

jButton2 = new javax.swing.JButton();


jTextField2 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Enter 10 Soil Moisture Values with space in between:");
jLabel2.setBackground(new java.awt.Color(204, 255, 204));
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 102, 102));
jLabel2.setText("STATISTICAL ANALYSIS PACKAGE");
jLabel3.setText("Possible tests:");
jList1.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Sum of SoilMoisture", "Maximum value", "Minimum value", "Mean
value", "Standard deviation", " " };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane2.setViewportView(jList1);
jButton1.setBackground(new java.awt.Color(153, 255, 255));
jButton1.setForeground(new java.awt.Color(0, 0, 255));
jButton1.setText("Run Test");
jButton1.setName("RunTest"); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);
}
});
jButton2.setBackground(new java.awt.Color(153, 255, 255));
jButton2.setForeground(new java.awt.Color(0, 0, 255));
jButton2.setText("Clear");
jButton2.setName("Clear"); // NOI18N
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel1))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(52, 52, 52)
.addComponent(jScrollPane2,
javax.swing.GroupLayout.PREFERRED_SIZE, 166,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE, 268,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGap(69, 69, 69)
.addComponent(jLabel2))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
379, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(35, 35, 35)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(67, 67, 67)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(31, 31, 31)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2))
.addContainerGap(36, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// Run test Button


int sum,max, min;
float avg;
double std;
String text;
int soilMoisture[]=new int[11];
String t=jTextField2.getText();
String s[]=t.split(" ");
for(int i=0;i<10;i++)
soilMoisture[i]= Integer.parseInt(s[i]);
switch (jList1.getSelectedIndex()) {

case 1: sum=getSum(soilMoisture);
text=(String) jList1.getSelectedValue()+": "+sum;
jTextField1.setText(text);
break;
case 2: min=getMin(soilMoisture);
text=(String) jList1.getSelectedValue()+": "+min;
jTextField1.setText(text);
break;
case 3: max=getMax(soilMoisture);
text=(String) jList1.getSelectedValue()+": "+max;
jTextField1.setText(text);
break;

case 4: sum=getSum(soilMoisture);
avg=sum/10;
text=(String) jList1.getSelectedValue()+": "+avg;
jTextField1.setText(text);
break;

case 5: std= getStd(soilMoisture);

text=(String) jList1.getSelectedValue()+": "+std;

jTextField1.setText(text);
break;
}
}
private int getSum(int soilMoisture[] )
{
int i;
//sum
int sum=0;
for(i=0;i<10;i++)
sum+= soilMoisture[i];
return sum;
}

private int getMin(int soilMoisture[] )


{
int min=soilMoisture[0];
for(int i=0;i<10;i++)
{
if(soilMoisture[i]<min)
min= soilMoisture[i];
}

return min;
}
private int getMax(int soilMoisture[] )
{
int max=soilMoisture[0];
for(int i=0;i<10;i++)
{
if(soilMoisture[i]<max)
max= soilMoisture[i];
}
return max;
}
private double getStd(int soilMoisture[] )
{
float avg=getSum(soilMoisture)/10;
int sum1=0;
for(int i=0;i<10;i++)
sum1+= Math.pow((soilMoisture[i]-avg),2);
sum1/= 9;
double std=Math.sqrt(sum1);
return std;
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

// Clear button
jTextField1.setText(null);
jTextField2.setText(null);

}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}

}
} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(AnalysisUI.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new AnalysisUI().setVisible(true);
}
});

}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}

Which production should be in the grammar for a language L = M*, where A is the start symbol
for M and S is the start symbol for L?
A.

S -> AS | ?

B.
S -> SA | ?

C.
S -> AS | A

D.
Either A or B

You might also like